﻿package 
{
	import flash.filters.BlurFilter;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.display.Shape;
	import flash.display.Sprite;	
	import flash.display.Bitmap;
	import flash.display.BitmapData;	
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;	
	import flash.geom.Point;	
	
	/*
	 * coded by moka 2009 / 06/ 11 
	 * name : motion light
	 * extend : particle simulation
	 */

	public class Main extends Sprite 
	{		
		private var bmp:Bitmap;
		private var bmpBuffer:BitmapData;
		private var px:Number; //前一個滑鼠水平座標
		private var py:Number; //前一個滑鼠垂直座標
		
		public function Main():void 
		{
			stage.scaleMode = "noScale"; // 設定場景不變形
			bmp = addChild(new Bitmap(new BitmapData(640, 480, true, 0xFF000000))) as Bitmap; // 場景呈現畫面			
			addEventListener(Event.ENTER_FRAME, onProcess); // loop 事件			
			(addChild(new TextField()) as TextField).htmlText = "<font color='#FFFFFF'>Moka's work 2009</font>"; // Moka's work 2009
		}		
		
		public function onProcess(e:Event):void {
			bmpBuffer = bmp.bitmapData.clone(); // 複製前一張場景圖		
			bmp.bitmapData.draw(bmpBuffer, new Matrix(), new ColorTransform(0, 0, 0,0.05)); // 繪製5%透明度bmpBuffer
			
			var shape:Shape = new Shape();
			shape.graphics.lineStyle(50, 0xFFFFFF); // 寬50px白色筆刷
			shape.graphics.lineTo(px - mouseX, py - mouseY); // 繪線
			
			bmp.bitmapData.draw(shape, new Matrix(1,0,0,1,mouseX,mouseY));// 繪製shape			
			bmp.bitmapData.applyFilter(bmp.bitmapData, bmp.bitmapData.rect, new Point(), new BlurFilter());// 套用模糊效果
			
			px = mouseX;
			py = mouseY;
		}
	}	
}